clear; if ispc; dbstop if error; end; rng('default');

input_folder = [fullfile(pwd, '..') filesep];

output_folder = input_folder;

%% load demand estimation results
list_variables = {'T','W1','W2','brand_descr','brand_geomkt_id','brand_id2','brandfile','brewer_id','brewer_loc_tbl',...
    'cov_var','craftdummy','demeaned_iv','demeaned_x','dim_price','dist_x',...
    'geo_tbl','geomkt','iS2_brand','iS2_brand_geomkt','iS2_geomkt',...
    'inc_mkt','ind_mkt_end','ind_mkt_start','ind_obs_brand','ind_obs_brand_geomkt','ind_obs_geomkt',...
    'logcutoff','logcutoff_craft','loginc','logincnorm','logshare','maxid','merge_id','micro_m_data','mktid',...
    'mktsize','mktsize_geomktyr','mo_dummy',...
    'n_obs_per_brand','n_obs_per_brand_geomkt','n_obs_per_geomkt','n_trips',...
    'owner_id','quantity',...
    'price','randomdraw','setup',...
    'store_county_id','use_micro','x_rand','x_rand2','yr'};

% load data and demand estimation functions
load([input_folder, 'est_demand.mat']);
load([input_folder, 'est_demand_variables_for_est.mat'], list_variables{:});
addpath(fullfile(pwd, '..', '1demand'));


% estimate standard errors of demand and mc parameters, draw these parameters from their distribution
est_linear_mc;

% compute min and max change in variable profits
est_product_entry_covariates;
